#!/bin/bash

# ----------------------------------------
# 定期备份mysql数据到七牛云
# 定期更新https证书
# ----------------------------------------

database=$1
echo "【开始备份 mysql 数据，库名：${database}】"

year=$(date +"%Y")
month=$(date +"%m")
day=$(date +"%d")

filename="${database}_${year}${month}${day}.sql"
filepath="/tmp/$filename"
rm -rf $filepath

echo "保存文件：$filepath"
docker exec -i mysql bash -c "mysqldump -uroot -p4fJhEtZ8Mne8 $database > $filepath"
docker cp mysql:$filepath $filepath

curl -X POST -F "file=@$filepath" "http://liufq.cn:18886/file/upload?directory=backup&isRename=false"